import type { IColumnsOption } from 'vc';
import { CellRenderMap, INDEX, COMPANY_NAME, INFO_SOURCE, PROVINCE, CITY, INDUSTRY_CATEGORY, BUSINESS_DATA, REGISTERED_CAPITAL } from '@/utils';

export function useTable() {
  const tableData = ref([]);

  const columns = ref<IColumnsOption[]>([
    { ...INDEX },
    { ...COMPANY_NAME },
    {
      title: '披露日期',
      field: 'noticeDate',
      width: 100,
      align: 'center',
      sortable: true,
      sortBy: 'noticeDate'
    },
    { ...INFO_SOURCE('dataSource') },
    {
      title: '资格证号',
      field: 'certificateNumber',
      width: 100,
      align: 'center',
      sortable: true,
      sortBy: 'certificateNumber',
      cellRender: {
        name: CellRenderMap.HighLight
      }
    },
    {
      title: '状态',
      field: 'isExpired',
      width: 100,
      align: 'center',
      slots: {
        default: ({ row }) => {
          const color = { 有效: 'revocation-03b915', 过期: 'revocation-aaaaaa' };
          const showText = row.isExpired ? '过期' : '有效';
          const className = 'revocation ' + color[showText];
          return row.isExpired === null ? (
            '-'
          ) : (
            <span title={showText} class={className}>
              {showText}
            </span>
          );
        }
      }
    },
    {
      title: '发证日期',
      field: 'periodOfValidityStartDate',
      width: 100,
      align: 'center',
      sortable: true,
      sortBy: 'periodOfValidityStartDate'
    },
    {
      title: '有效起止日期',
      field: 'periodOfValidityExpirationDate',
      width: 200,
      align: 'center',
      sortable: true,
      sortBy: 'periodOfValidityExpirationDate',
      slots: {
        default: ({ row }) => {
          const isShow = row.periodOfValidityStartDate || row.periodOfValidityExpirationDate;
          const showText = `${row.periodOfValidityStartDate || '-'} 至 ${row.periodOfValidityExpirationDate || '-'}`;
          return isShow ? <span title={showText}>{showText}</span> : '-';
        }
      }
    },
    { ...PROVINCE },
    { ...CITY },
    { ...INDUSTRY_CATEGORY },
    { ...BUSINESS_DATA },
    { ...REGISTERED_CAPITAL }
  ]);

  return {
    tableData,
    columns
  };
}
